<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Creates SNMP instance representing session to remote SNMP agent</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="snmp.close.html">SNMP::close</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="snmp.get.html">SNMP::get</a></div>
 <div class="up"><a href="class.snmp.html">SNMP</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="snmp.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SNMP::__construct</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.4.0)</p><p class="refpurpose"><span class="refname">SNMP::__construct</span> &mdash; <span class="dc-title">Creates SNMP instance representing session to remote <acronym title="Simple Network Management Protocol">SNMP</acronym> agent</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-snmp.construct-description">
  <h3 class="title">说明</h3>

  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SNMP::__construct()</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$version</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$hostname</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$community</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$timeout</code><span class="initializer"> = 1000000</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$retries</code><span class="initializer"> = 5</span></span>
  ]] )</div>

  <p class="para rdfs-comment">
   The function description goes here.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-snmp.construct-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>
<em><code class="parameter">version</code></em></dt>

    <dd>

     <p class="para">
      <acronym title="Simple Network Management Protocol">SNMP</acronym> protocol version:
      <strong><code>SNMP::VERSION_1</code></strong>, 
      <strong><code>SNMP::VERSION_2C</code></strong>, 
      <strong><code>SNMP::VERSION_3</code></strong>.
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">hostname</code></em></dt>

    <dd>

     <p class="para">
      The <acronym title="Simple Network Management Protocol">SNMP</acronym> agent. <em><code class="parameter">hostname</code></em> may be suffixed with
      optional <acronym title="Simple Network Management Protocol">SNMP</acronym> agent port after colon. IPv6 addresses must be enclosed in square
      brackets if used with port. If FQDN is used for <em><code class="parameter">hostname</code></em>
      it will be resolved by php-snmp library, not by Net-SNMP engine. Usage
      of IPv6 addresses when specifying FQDN may be forced by enclosing FQDN
      into square brackets. Here it is some examples:
     <table class="doctable table">
      
      
       <tbody class="tbody">
        <tr><td>IPv4 with default port</td><td>127.0.0.1</td></tr>

        <tr><td>IPv6 with default port</td><td>::1 or [::1]</td></tr>

        <tr><td>IPv4 with specific port</td><td>127.0.0.1:1161</td></tr>

        <tr><td>IPv6 with specific port</td><td>[::1]:1161</td></tr>

        <tr><td>FQDN with default port</td><td>host.domain</td></tr>

        <tr><td>FQDN with specific port</td><td>host.domain:1161</td></tr>

        <tr><td>FQDN with default port, force usage of IPv6 address</td><td>[host.domain]</td></tr>

        <tr><td>FQDN with specific port, force usage of IPv6 address</td><td>[host.domain]:1161</td></tr>

       </tbody>
      
     </table>

     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">community</code></em></dt>

    <dd>

     <p class="para">The purpuse of <em><code class="parameter">community</code></em> is
     <acronym title="Simple Network Management Protocol">SNMP</acronym> version specific:</p>
     <table class="doctable table">
      
      
       <tbody class="tbody">
        <tr><td>SNMP::VERSION_1</td><td><acronym title="Simple Network Management Protocol">SNMP</acronym> community</td></tr>

        <tr><td>SNMP::VERSION_2C</td><td><acronym title="Simple Network Management Protocol">SNMP</acronym> community</td></tr>

        <tr><td>SNMP::VERSION_3</td><td><acronym title="Simple Network Management Protocol">SNMP</acronym>v3 securityName</td></tr>

       </tbody>
      
     </table>

    </dd>

   
    
     <dt>
<em><code class="parameter">timeout</code></em></dt>

     <dd>

      <p class="para">
       The number of microseconds until the first timeout.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">retries</code></em></dt>

     <dd>

      <p class="para">
       The number of retries in case timeout occurs.
      </p>
     </dd>

    
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-snmp.construct-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns SNMP object representing remote <acronym title="Simple Network Management Protocol">SNMP</acronym> agent.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-snmp.construct-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   <span class="methodname"><strong>SNMP::__construct()</strong></span> throws an exception when
   parameters count or types are wrong or unknown <acronym title="Simple Network Management Protocol">SNMP</acronym>
   protocol version specified.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-snmp.construct-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="snmp.construct.example.basic">
   <p><strong>Example #1 Fetching sysLocation</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$session&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SNMP</span><span style="color: #007700">(</span><span style="color: #0000BB">SNMP</span><span style="color: #007700">::</span><span style="color: #0000BB">VERSION_1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"127.0.0.1"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"public"</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$sysdescr&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #DD0000">"sysDescr.0"</span><span style="color: #007700">);<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$sysdescr</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
STRING: Test server
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-snmp.construct-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="methodname"><a href="snmp.close.html" class="methodname" rel="rdfs-seeAlso">SNMP::close()</a> - Close SNMP session</span></li>
  </ul>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="snmp.close.html">SNMP::close</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="snmp.get.html">SNMP::get</a></div>
 <div class="up"><a href="class.snmp.html">SNMP</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
